package com.hippomeetsskunk.savanna.types.world;

public class TimePeriod {

	private int beginOfPeriod;
	private int endOfPeriod;
	
	public TimePeriod(int beginOfPeriod, int endOfPeriod){
		this.beginOfPeriod = beginOfPeriod;
		this.endOfPeriod = endOfPeriod;
	}
	
	public boolean isWithin(int t){
		return (t >= beginOfPeriod && t <= endOfPeriod);
	}

	public boolean overlapsWith(TimePeriod period) {
		return (getOverlappingDays(period) > 0);
	}
	
	public int getOverlappingDays(TimePeriod period){
		final int b = Math.max(beginOfPeriod, period.beginOfPeriod);
		final int e = Math.min(endOfPeriod, period.endOfPeriod);
		
		final int d = Math.max(0, (b - e) + 1);
		return d;
	}
}
